package com.dys.hejiayuncommunity.common.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @className: com.dys.hejiayuncommunity.common.handler.MyMetaObjectHandler
 * @description: mybatis-plus自动填充属性配置
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/12/05 22:38
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    /**
     * 添加时需要填充的属性
     *
     * @param metaObject 元数据对象
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        // 根据属性名称设置要填充的属性值
        this.strictInsertFill(metaObject, "createBy", String.class, "admin");
        this.strictInsertFill(metaObject, "updateBy", String.class, "admin");
        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "updateTime", Date.class, new Date());

    }

    /**
     * 修改时需要填充的属性
     *
     * @param metaObject 元数据对象
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "updateBy", String.class, "admin");
        this.strictInsertFill(metaObject, "updateTime", Date.class, new Date());
    }
}
